
function createCheckingStudentTab(data){
	var tab=document.getElementById("checkingStudentTab");
	for(var i=0;i<data.length;i++){

	var tr=document.createElement("tr");

	var td=document.createElement("td");
	td.textContent=data[i].student_username;
	tr.appendChild(td)

	var td=document.createElement("td");
	td.textContent=data[i].student_chinesename;
	tr.appendChild(td)

	var td=document.createElement("td");
	var delButton=document.createElement("button");
	delButton.className="btn btn-xs btn-danger"
	delButton.textContent="拒绝"
	delButton.setAttribute("teacherandstudent_id",data[i].id)
	delButton.onclick=function(){
		var id=this.getAttribute("teacherandstudent_id")
		$.ajax({
			"url":"/reject_student/",
			"error":errorAjax,
			"beforeSend":start_load_pic,
			"complete":stop_load_pic,
			"data":{"sid":id},
			"dataType":"jsonp",
			"success":function(data){
				if(!data.status){
					showErrorInfo(data.content)
					return false;
				}
				alert("已拒绝!")
				window.location.reload()
			}
		})
	}
	var passButton=document.createElement("button");
	passButton.className="btn btn-xs btn-success"
	passButton.style.marginLeft="3px"
	passButton.textContent="同意"
	passButton.setAttribute("teacherandstudent_id",data[i].id)
	passButton.onclick=function(){
		var id=this.getAttribute("teacherandstudent_id")
		$.ajax({
			"url":"/accept_student/",
			"error":errorAjax,
			"beforeSend":start_load_pic,
			"complete":stop_load_pic,
			"data":{"sid":id},
			"dataType":"jsonp",
			"success":function(data){
				if(!data.status){
					showErrorInfo(data.content)
					return false;
				}
				alert("已通过!")
				window.location.reload()
			}
		})
	}
	td.appendChild(delButton)
	td.appendChild(passButton)
	tr.appendChild(td)
	
	tab.appendChild(tr)

	}
}

function createJoinedStudentTab(data){
	var tab=document.getElementById("joinedStudentTab");
	for(var i=0;i<data.length;i++){

	var tr=document.createElement("tr");

	var td=document.createElement("td");
	td.textContent=data[i].student_username;
	tr.appendChild(td)

	var td=document.createElement("td");
	td.textContent=data[i].student_chinesename;
	tr.appendChild(td)

	var td=document.createElement("td");
	var delButton=document.createElement("button");
	delButton.className="btn btn-xs btn-danger"
	delButton.textContent="删除"
	delButton.setAttribute("teacherandstudent_id",data[i].id)
	delButton.onclick=function(){
		if(confirm("真的要删除吗？")===false){
				return false
			}
		var sid=this.getAttribute("teacherandstudent_id")
		$.ajax({
			"url":"/delete_student/",
			"error":errorAjax,
			"complete":stop_load_pic,
			"beforeSend":start_load_pic,
			"data":{"sid":sid},
			"dataType":"jsonp",
			"success":function(data){
				if(!data.status){
					showErrorInfo(data.content)
					return false;
				}
				alert("操作成功！")
				window.location.reload()
			}
		})
	}
	td.appendChild(delButton)
	tr.appendChild(td)
	
	tab.appendChild(tr)

	}
}
function getCheckingStudent(){
	jQuery.ajax({
	"url":"/get_chekcing_student/",
	"dataType":"jsonp",
	"data":{"sid":getQ().sid},
        "error": errorAjax,
        "beforeSend": start_load_pic,
        "complete": stop_load_pic,
        "success": function (data) {
            if (!data.status) {
                showErrorInfo(data.content); return false; }
            else {
		createCheckingStudentTab(data.content);
            }
         }
	})
	
}
function getJoinedStudent(){
	jQuery.ajax({
	"url":"/get_joined_student/",
	"dataType":"jsonp",
	"data":{"sid":getQ().sid},
        "error": errorAjax,
        "beforeSend": start_load_pic,
        "complete": stop_load_pic,
        "success": function (data) {
            if (!data.status) {
                showErrorInfo(data.content); return false; }
            else {
		createJoinedStudentTab(data.content);
            }
         }
	})
	
}
$(function(){
	getJoinedStudent();
	getCheckingStudent();
})
